﻿using System;

namespace Mates
{
    /// <summary>
    /// Versió pura de Vector3i, no inclou conversions de tipus
    /// </summary>
    public struct Vector3i
    {
        public Vector3i(int x, int y, int z)
        {
            this.x = x;
            this.y = y;
            this.z = z;
        }
        public int x;
        public int y;
        public int z;
        public static Vector3i Zero = new Vector3i(0, 0, 0);

        public override bool Equals(object obj)
        {
            if (obj is Vector3i)
            {
                Vector3i other = (Vector3i)obj;
                return this.x == other.x && this.y == other.y && this.z == other.z;
            }
            return base.Equals(obj);
        }
        public static bool operator ==(Vector3i a, Vector3i b)
        {
            return a.x == b.x && a.y == b.y && a.z == b.z;
        }
        public static bool operator !=(Vector3i a, Vector3i b)
        {
            return !(a.x == b.x && a.y == b.y && a.z == b.z);
        }

        public static Vector3i operator +(Vector3i a, Vector3i b)
        {
            return new Vector3i(a.x + b.x, a.y + b.y, a.z + b.z);
        }

        public override int GetHashCode()
        {
            int hash = 23;
            unchecked
            {
                hash = hash * 37 + x;
                hash = hash * 37 + y;
                hash = hash * 37 + z;
            }
            return hash;
        }
        public int GetDistanceSquared(Vector3i vector2)
        {
            int dx = this.x - vector2.x;
            int dy = this.y - vector2.y;
            int dz = this.z - vector2.z;
            return (dx * dx) + (dy * dy) + (dz * dz);
        }
        public override string ToString()
        {
            return ("vector3i (" + x + "," + y + "," + z + ")");
        }
    }
}
